package com.petAdoption.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.petAdoption.manager.entity.Petage;
import com.petAdoption.manager.mapper.PetageMapper;
import com.petAdoption.manager.service.IPetageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王倩茹
 * @since 2023-08-28
 */
@Service
public class PetageServiceImpl extends ServiceImpl<PetageMapper, Petage> implements IPetageService {

    @Resource
    private PetageMapper petageMapper;

    @Override
    public List<Petage> findAll() {
        return petageMapper.selectList(null);
    }

    @Override
    public int delPetAge(Integer petageId) {
        return petageMapper.deleteById(petageId);
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("petAge_id",petageId);
//
//        return petageMapper.delete(queryWrapper);
    }


    @Override
    public int addPetAge(Petage petage) {
        return petageMapper.insert(petage);
    }

//    @Override
//    public int updatePetType(Petage petage) {
//        UpdateWrapper updateWrapper = new UpdateWrapper<>();
//        updateWrapper.set("petAge_type",petage.getPetageType());
//        updateWrapper.like("petAge_id",petage.getPetageId());
//
//        int update = petageMapper.update(null, updateWrapper);
//        return update;
//    }

    @Override
    public int updatePetType(Petage petage) {

        return petageMapper.updateById(petage);
    }


//    @Override
//    public boolean updateById(Petage petage) {
//        UpdateWrapper updateWrapper = new UpdateWrapper<>();
//        updateWrapper.set("petAge_type",petage.getPetageType());
//        updateWrapper.like("petAge_id",petage.getPetageId());
//
//        int update = petageMapper.update(null, updateWrapper);
//        if (update>0)return true;
//        return false;
//    }

}
